class Watcher {
    constructor() {
        this.deps = {};
    }
    collect(type,func){
        if(this.deps[type]){
            this.deps[type].push(func)
        } else {
            this.deps[type] = [func]
        }
    }
    emit(type){
        this.deps[type].forEach((item)=>{
            item();
        })
    }
    delete(type){
        this.deps[type] = [];
    }
}

class Deps {
    constructor(id) {
        this.id = id;
        this.update = ()=> {
            console.log("更新dep",this.id)
        }
    }
}
const watcher = new Watcher();
const dep1 = new Deps(1);
const dep2 = new Deps(2);
const dep3 = new Deps(3);
watcher.collect('A',dep1.update);
watcher.collect('A',dep2.update);
watcher.collect('A',dep3.update);
watcher.emit('A');
watcher.delete('A');
watcher.emit('A');
watcher.collect('A',dep2.update);
watcher.collect('B',dep3.update);
watcher.emit('A')
watcher.emit('B')